<?php

namespace App\Models\Application;

use Eloquent as Model;
use Illuminate\Database\Eloquent\SoftDeletes;

/**
 * Class ColumnRecommend
 * @package App\Models\Application
 * @version July 2, 2018, 2:41 pm CST
 *
 * @property \App\Models\Application\Column column
 * @property string name
 * @property string title
 * @property string description
 * @property integer column_id
 * @property string area
 * @property string x_coordinate
 */
class ColumnRecommend extends Model
{
    use SoftDeletes;

    public $table = 'column_recommends';

    protected $dates = ['deleted_at'];

    public $fillable = [
        'name',
        'title',
        'description',
        'column_id',
        'area',
    ];

    /**
     * The attributes that should be casted to native types.
     *
     * @var array
     */
    protected $casts = [
        'name'        => 'string',
        'title'       => 'string',
        'description' => 'string',
        'column_id'   => 'integer',
        'area'        => 'string',
    ];

    /**
     * Validation rules
     *
     * @var array
     */
    public static $rules = [
        'area' => 'required|max:50',
    ];

    /**
     * @return \Illuminate\Database\Eloquent\Relations\HasOne
     **/
    public function column()
    {
        return $this->hasOne(\App\Models\Entity\Column\Column::class, 'id', 'column_id');
    }

    /**
     * @return \Illuminate\Database\Eloquent\Relations\HasOne
     * 栏目推荐数据
     **/
    public function columnrecommenddatas()
    {
        return $this->belongsToMany(\App\Models\Application\ColumnRecommendData::class, 'column_recommend_column_recommend_datas', 'column_recommend_id', 'column_recommend_data_id');
    }

}
